function gray = grayTable(n)
if n <= 0
  error("n should be bigger than 1");
end

gray = zeros(2^floor(n), 1);
gray(1) = 0;
gray(2) = 1;
for i = 2:n
  for j = 0:2^(i-1)-1
    gray(2^i-j) = gray(j+1) + 2^(i-1);
  end
end
  
endfunction

